/*
 * Example01.java
 *
 * Created on 19 gennaio 2008, 17.17
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package it.cnr.icib.flora2engine.examples;

import it.cnr.icib.flora2engine.Flora2;
import java.util.Iterator;

import net.sourceforge.flora.javaAPI.src.FloraObject;

/**
 *
 * @author Nino
 */
public class Example01 {
    
    /** Creates a new instance of Example01 */
    public Example01() {
    }
    
    public static void main(String[] args) {
        
    	Flora2 session ;
        String curDir = System.getProperty("user.dir");
        
        System.out.println(curDir);
        
        String OS= System.getProperties().getProperty("os.name");
        System.out.println(OS);
        
        
        if (OS.contains("Mac")){
            session = new Flora2(curDir + "/xsb_mac_337/config/i386-apple-darwin11.4.2/bin",
            		curDir + "/xsb_mac_337/packages/flora2");

        }else if(OS.contains("Win")){
        	session = new Flora2(curDir+ "/xsb_win_31/config/x86-pc-windows/bin",
        			curDir+ "/xsb_win_31/packages/flora2");
        }else{ //Linux
        	session = new Flora2(curDir+"/xsb_lin/config/x86-pc-windows/bin",
        			curDir+"/xsb_lin/packages/flora2");
        }
        
             
        session.setPath(curDir + "/florasrc");
        
        String fileName = "person";
        String moduleName = "test";
        
        
        if(fileName == null || fileName.trim().length() == 0) {
            System.out.println("Invalid path to example file!");
            System.exit(0);
        }
        
        session.loadFile(fileName,moduleName);
        
        /* Examples of uses of the low-level Java-FLORA-2 API */
        // Querying persons
        String command = "?X:person@test.";        
        
        System.out.println("Query:"+command);
        Iterator<FloraObject> personObjs = session.ExecuteQuery(command);
        /* Printing out persons  */
        while (personObjs.hasNext()) {
            Object personObj = personObjs.next();
            System.out.println("Person Id: "+personObj);
        }
        
        
        
        // Close session and good bye
        session.close();
        System.exit(0);
    }
}
